Scotland | ITP JAN-2026 | Tuan Nguyen | Sprint 3 | 2- Practice-tdd#1258
Scotland | ITP JAN-2026 | Tuan Nguyen | Sprint 3 | 2- Practice-tdd#1258Jacknguyen4438 wants to merge 3 commits intoCodeYourFuture:mainfrom
Conversation
| if (findCharacters.length < 1) { | ||
| throw new Error("findCharacters must be a single character"); | ||
| } |
There was a problem hiding this comment.
Is findCharacters allowed to be more than one characters?
There was a problem hiding this comment.
Thank you for feed back, I see that I have make some validation error. I can see that instead of validation for just a specific character. So instead I will change this test so that is can check correctly
There was a problem hiding this comment.
Could consider testing a few more samples in this script - higher chance to detect bugs in code.
The original specification did not clearly state whether the character match should be case-sensitive.
Most people would probably assume that it is, but to demonstrate our understanding or clarify the assumption we made,
we could add test cases to convey this. For examples,
- A case to show that the match is case sensitive
- A case to show that the function is expected to work also for non-alphabets
There was a problem hiding this comment.
@cjyuan Thank you for the suggestion here is my jest test case for this 2 scenario:
// Scenario: Case-sensitive matching
// Given a string containing both uppercase and lowercase versions of a letter,
// When the function is called with a lowercase character,
// Then it should only count the lowercase occurrences.
test("should treat character matching as case-sensitive", () => {
expect(countChar("AaAa","A")).toEqual(2);
});
// Scenario: Non-alphabet characters
// Given a string containing digits and symbols,
// When the function is called with a non-alphabet character,
// Then it should correctly count occurrences of that character.
test("should count occurrences of non-alphabet characters", () => {
expect(countChar("1-2-3-1-1","1")).toEqual(3);
});
| if(num % 100 === 11 ||num % 100 === 12 || num % 100 === 13 ){ | ||
| return `${num}th`; | ||
| } | ||
| switch( true ){ | ||
| case num % 10 === 1 : return `${num}st`; | ||
| case num % 10 === 2 : return `${num}nd`; | ||
| case num % 10 === 3 : return `${num}rd`; | ||
| default : return `${num}th`; | ||
| } |
There was a problem hiding this comment.
Can you look up the pros and cons between these two styles of expressing the code?
if(num % 100 === 11 ||num % 100 === 12 || num % 100 === 13 ){
const lastTwoDigits = num % 100;
if (lastTwoDigits === 11 || lastTwoDigits === 12 || lastTwoDigits === 13 ) {
?
There was a problem hiding this comment.
@cjyuan Thank you for the feed back,
I see that that for the first line the main pro is that :
- The pros is that the code shorter, no extra variable and is good for when 1 argument pass to each condition.
- The cons is that the code it harder to understand for some new beginner and might caught with unexpected error. Also the argument num is now pass 3 time for each condition and it can cause issue if the code is broke outside the function.
For the second line I see that:
- The pros of this line is that is more solid and safer then the first line. It help other coder or beginner to understand the code easier. Also the value now store inside a container that can be used safely and if need be can be change later.
The cons for this line of code as far as I can see is that is only add 1 more line of code.
So after I see both Pros and cons of these 2 line, understand for the best I will used the second line of code since is more save and easier to change and fix. I will make this change inside my code. Thank you.
| } | ||
|
|
||
| // This allow float number to be round into it nearest integer. | ||
| num = Math.round(num); |
There was a problem hiding this comment.
Why do you decide to round the numbers with decimal places? Why not reject them?
There was a problem hiding this comment.
For this one I, the main reason is that since I would like to for the function to work even is the user pass a float number value. When pass inside the function the argument num will automatically will be round to their nearest number then do the reminder. But I see now is might caught the issue since it will return not what the user put in so I will max change that reject the decimal value.
| // Case 5: All other numbers | ||
| // When the number does not end with 1, 2, or 3, | ||
| // Then the function should append "th". | ||
| test("should append 'th' for all other numbers", () => { |
There was a problem hiding this comment.
When a test fails with the message "... all other numbers", it may be unclear what "other numbers" actually refers to.
Can you revise the test description to make it more informative?
There was a problem hiding this comment.
Thank you for the feed back I will fix it right away
| switch (true){ | ||
| case repeatCount === 0 : return ""; | ||
| default: return fullString.repeat(repeatCount) ; | ||
| }; |
There was a problem hiding this comment.
What do you think about this writing style?
if (repeatCount === 0) return "":
return fullString.repeat(repeatCount);
There was a problem hiding this comment.
Thank you for the reply , I think that if I used the same method as you using with this line code. It will run and return the value just fine since is a if else statement but more shorthand compact. I understand that by using switch case is make make the code look better but in long term can cause some issue in the long run. So for the best I will try this if else style for easier reading and maintain the code.
|
@cjyuan Hello thank you for the review, I see there are many part that need to be fix and improve. I will check all 5 part that you would like me to explain and fix each of them. When I finish I will mention you again to ask for a review. |
Learners, PR Template
Self checklist
Changelist
I have done practice and fully understand how to write a test for both normal JS and Jest test.
Questions
No Question.